//
//  LotteryStatistic.swift
//  MakeMoney
//
//  Created by fan zhiqiang on 2024/12/19.
//

import Foundation

class LotteryStatistics {
    var num1Count: Int = 0
    var num2Count: Int = 0
    var num3Count: Int = 0
    var num4Count: Int = 0
    var num5Count: Int = 0
    var num6Count: Int = 0
    var num7Count: Int = 0
    var num8Count: Int = 0
    var num9Count: Int = 0
    var num10Count: Int = 0
    var num11Count: Int = 0
    var num12Count: Int = 0
    var num13Count: Int = 0
    var num14Count: Int = 0
    var num15Count: Int = 0
    var num16Count: Int = 0
    var num17Count: Int = 0
    var num18Count: Int = 0
    var num19Count: Int = 0
    var num20Count: Int = 0
    var num21Count: Int = 0
    var num22Count: Int = 0
    var num23Count: Int = 0
    var num24Count: Int = 0
    var num25Count: Int = 0
    var num26Count: Int = 0
    var num27Count: Int = 0
    var num28Count: Int = 0
    var num29Count: Int = 0
    var num30Count: Int = 0
    var num31Count: Int = 0
    var num32Count: Int = 0
    var num33Count: Int = 0
    var num34Count: Int = 0
    var num35Count: Int = 0
    
    var no1Count: Int = 0
    var no2Count: Int = 0
    var no3Count: Int = 0
    var no4Count: Int = 0
    var no5Count: Int = 0
    var no6Count: Int = 0
    var no7Count: Int = 0
    var no8Count: Int = 0
    var no9Count: Int = 0
    var no10Count: Int = 0
    var no11Count: Int = 0
    var no12Count: Int = 0
    
    var useBall1Count: Int = 0
    var useBall2Count: Int = 0
    var useBall3Count: Int = 0
    
    var numAverage: Double {
        Double(num1Count + num2Count + num3Count + num4Count + num5Count + num6Count + num7Count + num8Count + num9Count + num10Count +
        num11Count + num12Count + num13Count + num14Count + num15Count + num16Count + num17Count + num18Count + num19Count + num20Count +
        num21Count + num22Count + num23Count + num24Count + num25Count + num26Count + num27Count + num28Count + num29Count + num30Count +
         num31Count + num32Count + num33Count + num34Count + num35Count) / 35.0
    }
    
    var noAverage: Double {
        Double(no1Count + no2Count + no3Count + no4Count + no5Count + no6Count +
               no7Count + no8Count + no9Count + no10Count + no11Count + no12Count) / 12.0
    }
    
    var ballAverage: Double {
        Double(useBall1Count + useBall2Count + useBall3Count) / 3.0
    }
    
    var frontCountDictionary = [Int : Int]()
    var hindCountDictionary = [Int : Int]()
    var ballCountDictionary = [Int : Int]()
}


@Observable class TestLottery: Identifiable, Codable {
    enum CodingKeys: String, CodingKey {
        case _dateStr = "date"
        case _id = "id"
        case _lotteryBall = "lotteryBall"
        case _lotteryFront1 = "lotteryFront1"
        case _lotteryFront2 = "lotteryFront2"
        case _lotteryFront3 = "lotteryFront3"
        case _lotteryFront4 = "lotteryFront4"
        case _lotteryFront5 = "lotteryFront5"
        case _lotteryFrontSum = "lotteryFrontSum"
        case _lotteryHind1 = "lotteryHind1"
        case _lotteryHind2 = "lotteryHind2"
        case _lotteryHindSum = "lotteryHindSum"
        case _lotteryTotalSum = "lotteryTotalSum"
        case _meanDifferFront1 = "meanDifferFront1"
        case _meanDifferFront2 = "meanDifferFront2"
        case _meanDifferFront3 = "meanDifferFront3"
        case _meanDifferFront4 = "meanDifferFront4"
        case _meanDifferFront5 = "meanDifferFront5"
        case _meanDifferHind1 = "meanDifferHind1"
        case _meanDifferHind2 = "meanDifferHind2"
        case _subSumMean21 = "subSumMean21"
        case _subSumMean32 = "subSumMean32"
        case _subSumMean43 = "subSumMean43"
        case _subSumMean54 = "subSumMean54"
        case _subSumMean76 = "subSumMean76"
        case _subtractLottery21 = "subtractLottery21"
        case _subtractLottery32 = "subtractLottery32"
        case _subtractLottery43 = "subtractLottery43"
        case _subtractLottery54 = "subtractLottery54"
        case _subtractLottery76 = "subtractLottery76"
        case _subtractSum21 = "subtractSum21"
        case _subtractSum32 = "subtractSum32"
        case _subtractSum43 = "subtractSum43"
        case _subtractSum54 = "subtractSum54"
        case _subtractSum76 = "subtractSum76"
        case _subtractSumLottery = "subtractSumLottery"
        case _sumFront1 = "sumFront1"
        case _sumFront2 = "sumFront2"
        case _sumFront3 = "sumFront3"
        case _sumFront4 = "sumFront4"
        case _sumFront5 = "sumFront5"
        case _sumHind1 = "sumHind1"
        case _sumHind2 = "sumHind2"
        case _sumMeanFront1 = "sumMeanFront1"
        case _sumMeanFront2 = "sumMeanFront2"
        case _sumMeanFront3 = "sumMeanFront3"
        case _sumMeanFront4 = "sumMeanFront4"
        case _sumMeanFront5 = "sumMeanFront5"
        case _sumMeanHind1 = "sumMeanHind1"
        case _sumMeanHind2 = "sumMeanHind2"
        case _type = "type"
        case _typeAverage = "typeAverage"
        case _yearId = "yearId"
    }
    
    var dateStr: String
    var id: Int
    var lotteryBall: Int
    var lotteryFront1: Int
    var lotteryFront2: Int
    var lotteryFront3: Int
    var lotteryFront4: Int
    var lotteryFront5: Int
    var lotteryFrontSum: Int
    var lotteryHind1: Int
    var lotteryHind2: Int
    var lotteryHindSum: Int
    var lotteryTotalSum: Int
    var meanDifferFront1: Double
    var meanDifferFront2: Double
    var meanDifferFront3: Double
    var meanDifferFront4: Double
    var meanDifferFront5: Double
    var meanDifferHind1: Double
    var meanDifferHind2: Double
    var subSumMean21: Double
    var subSumMean32: Double
    var subSumMean43: Double
    var subSumMean54: Double
    var subSumMean76: Double
    var subtractLottery21: Int
    var subtractLottery32: Int
    var subtractLottery43: Int
    var subtractLottery54: Int
    var subtractLottery76: Int
    var subtractSum21: Int
    var subtractSum32: Int
    var subtractSum43: Int
    var subtractSum54: Int
    var subtractSum76: Int
    var subtractSumLottery: Int
    var sumFront1: Int
    var sumFront2: Int
    var sumFront3: Int
    var sumFront4: Int
    var sumFront5: Int
    var sumHind1: Int
    var sumHind2: Int
    var sumMeanFront1: Double
    var sumMeanFront2: Double
    var sumMeanFront3: Double
    var sumMeanFront4: Double
    var sumMeanFront5: Double
    var sumMeanHind1: Double
    var sumMeanHind2: Double
    var type: String
    var typeAverage: String
    var yearId: Int
    
    static let strategy = Date.ParseStrategy(format: "\(year: .defaultDigits)-\(month: .defaultDigits)-\(day: .defaultDigits)", timeZone: .gmt)
        
    var date: Date {
        guard let date = try? Date(dateStr, strategy: Self.strategy) else {
            return Date()
        }
        return date
    }
    
    /*
    func encode(to encoder: any Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(self.id, forKey: ._id)
        try container.encode(self.yearId, forKey: ._yearId)
        try container.encode(self.dateStr, forKey: ._dateStr)
        try container.encode(self.num1, forKey: ._num1)
        try container.encode(self.num2, forKey: ._num2)
        try container.encode(self.num3, forKey: ._num3)
        try container.encode(self.num4, forKey: ._num4)
        try container.encode(self.num5, forKey: ._num5)
        try container.encode(self.no1, forKey: ._no1)
        try container.encode(self.no2, forKey: ._no2)
        try container.encode(self.useBall, forKey: ._useBall)
        try container.encode(self.type, forKey: ._type)
        try container.encode(self.averageType, forKey: ._averageType)
    }
    
    required init(from decoder: any Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        self.id = try container.decode(String.self, forKey: ._id)
        self.yearId = try container.decode(String.self, forKey: ._yearId)
        self.dateStr = try container.decode(String.self, forKey: ._dateStr)
        self.num1 = try container.decode(String.self, forKey: ._num1)
        self.num2 = try container.decode(String.self, forKey: ._num2)
        self.num3 = try container.decode(String.self, forKey: ._num3)
        self.num4 = try container.decode(String.self, forKey: ._num4)
        self.num5 = try container.decode(String.self, forKey: ._num5)
        self.no1 = try container.decode(String.self, forKey: ._no1)
        self.no2 = try container.decode(String.self, forKey: ._no2)
        self.useBall = try container.decode(String.self, forKey: ._useBall)
        self.type = try container.decode(String.self, forKey: ._type)
        self.averageType = try container.decode(String.self, forKey: ._averageType)
    }
    */
}
